package cn.xiaobai.captcha.handler.captchatype;

import cn.xiaobai.captcha.config.CaptchaProperties;
import cn.xiaobai.captcha.utils.MathCaptchaResultUtils;
import com.wf.captcha.ArithmeticCaptcha;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author yangdaji
 * @Date 2024/4/18
 * @PackageName cn.xiaobai.captcha.handler.captchatype
 * @ClassName MathCaptchaHandler
 */
@Slf4j
public class MathCaptchaHandlerAbstract extends AbstractCaptchaAbstractTypeHandler {

    {
        log.info("算术验证码处理器");
    }

    public MathCaptchaHandlerAbstract() {
    }

    public MathCaptchaHandlerAbstract(CaptchaProperties captchaProperties) {
        super(captchaProperties);
    }

    @Override
    public String createGeneral() {
        return math();
    }


    /**
     * 算术验证码
     *
     * @return
     */
    private String math() {
        /**
         * 需要处理的问题:
         * 获取的算术只是一个算术方程,并没有结果? 测试看看
         */
        log.info("算术验证码生成中....");
        //获取算术验证码字符串
        ArithmeticCaptcha arithmeticCaptcha = new ArithmeticCaptcha();
        String math = MathCaptchaResultUtils.captchaMathResult(arithmeticCaptcha.getArithmeticString());
        log.info("算术验证码生成完成,即将写入流中!");
        //将验证码放入流中
        arithmeticCaptcha.out(this.getOutputStream());
        return math;
    }
}
